import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GoodsVO, GoodsForm, GoodsQuery } from '@/api/business/goods/types';

/**
 * 查询商城商品列表
 * @param query
 * @returns {*}
 */

export const listGoods = (query?: GoodsQuery): AxiosPromise<GoodsVO[]> => {
  return request({
    url: '/business/goods/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商城商品详细
 * @param goodsId
 */
export const getGoods = (goodsId: string | number): AxiosPromise<GoodsVO> => {
  return request({
    url: '/business/goods/' + goodsId,
    method: 'get'
  });
};

/**
 * 新增商城商品
 * @param data
 */
export const addGoods = (data: GoodsForm) => {
  return request({
    url: '/business/goods',
    method: 'post',
    data: data
  });
};

/**
 * 修改商城商品
 * @param data
 */
export const updateGoods = (data: GoodsForm) => {
  return request({
    url: '/business/goods',
    method: 'put',
    data: data
  });
};

/**
 * 删除商城商品
 * @param goodsId
 */
export const delGoods = (goodsId: string | number | Array<string | number>) => {
  return request({
    url: '/business/goods/' + goodsId,
    method: 'delete'
  });
};
